import Vue from 'vue'
import VueRouter from 'vue-router';
/*import Home from './components/Home.vue';
import User from './components/user/User.vue';
import StockDetail from './components/stock/StockDetail.vue';*/

Vue.use(VueRouter);

const path = "./";

const routers = [{
	path: "/",
	redirect: "/home"
}, {
	path: "/home",
	component: resolve => require([path + 'components/Home'], resolve),
	name: "home",
	meta: {
		title: "首页"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/user/:id",
	component: resolve => require([path + 'components/user/User'], resolve),
	name: "user",
	meta: {
		title: "用户中心"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/signin",
	component: resolve => require([path + 'components/user/signin'], resolve),
	name: "signin",
	meta: {
		title: "用户登录"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/signup",
	component: resolve => require([path + 'components/user/signup'], resolve),
	name: "signup",
	meta: {
		title: "用户注册"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/signout",
	component: resolve => require([path + 'components/user/signout'], resolve),
	name: "signout",
	meta: {
		title: "退出登录"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/stock-detail/:id",
	component: resolve => require([path + 'components/stock/StockDetail'], resolve),
	name: "stock-detail",
	meta: {
		title: "股票详情"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/news-detail/:cid/:datetime/:id",
	component: resolve => require([path + 'components/news/news-detail'], resolve),
	name: "news-detail",
	meta: {
		title: "新闻详情"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/download-app/:datetime/:id",
	component: resolve => require([path + 'components/download-app/download-app'], resolve),
	name: "download-app",
	meta: {
		title: "app下载"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/channel/:cid",
	component: resolve => require([path + 'components/Channel'], resolve),
	name: "channel",
	meta: {
		title: "频道首页"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/search/:key",
	component: resolve => require([path + 'components/search/search'], resolve),
	name: "search",
	meta: {
		title: "搜索首页"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/getpassword",
	component: resolve => require([path + 'components/user/get-password'], resolve),
	name: "getpassword",
	meta: {
		title: "找回密码"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}, {
	path: "/resetpassword",
	component: resolve => require([path + 'components/user/reset-password'], resolve),
	name: "resetpassword",
	meta: {
		title: "忘记密码"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/mall",
	component: resolve => require([path + "components/mall/mall-home"], resolve),
	name: "mall",
	meta: {
		title: "在线商城"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/goods-detail/:cid/:id",
	component: resolve => require([path + "components/mall/mall-goods-detail"], resolve),
	name: "goodsDetail",
	meta: {
		title: "商品详情"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/goods-similarity/:cid/:id",
	component: resolve => require([path + "components/mall/mall-goods-similarity"], resolve),
	name: "goodsSimilarity",
	meta: {
		title: "商品对比"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/goods-sales/:id",
	component: resolve => require([path + "components/mall/mall-goods-sales"], resolve),
	name: "goodsSales",
	meta: {
		title: "促销商品"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/goods-addCart/:cid/:id",
	component: resolve => require([path + "components/mall/mall-goods-addCart"], resolve),
	name: "addCart",
	meta: {
		title: "购物车"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/shops/:id",
	component: resolve => require([path + "components/mall/mall-shops"], resolve),
	name: "mallShopsHome",
	meta: {
		title: "购物车"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
},{
	path: "/shops-allgoods/:id",
	component: resolve => require([path + "components/mall/mall-shops-allgoods"], resolve),
	name: "mallShopsAllGoods",
	meta: {
		title: "购物车"
	},
	beforeEnter: function(to, from, next) {
		console.log(to, from)
		next();
	}
}];

const router = new VueRouter({
	//mode: "history",
	base: "/",
	routes: routers
});

router.beforeEach((to, from, next) => {
	if (to.meta.title) {
		document.title = to.meta.title
	}
	next();
})

export default router;